import axios from 'axios';

// 1. 初始状态.
const state = () => ({
    logs: [],
});

// 2. 计算属性.
const getters = {};

// 3. 异步修改.
const actions = {
    loadLogLevel({ state }, iid) {
        axios.get(`/log/${iid}`).then((res) => {
            state.logs = Object.entries(res.data.loggers).map((item, v) => ({
                key: v,
                name: item[0],
                level: item[1].effectiveLevel,
            }));
        });
    },
    // eslint-disable-next-line no-unused-vars
    changeLogLevel({ state }, payload) {
        const { instance, name, level } = payload;

        axios.post('/log/settingLog', {
            instanceId: instance,
            logName: name,
            logLevel: level,
            // eslint-disable-next-line no-unused-vars
        }).then((_) => {});
    },
};

// 4. 同步修改.
const mutations = {
};

// 5. 模块导出.
export default {
    namespaced: true,
    state,
    getters,
    actions,
    mutations,
};
